package com.bee.剑指offer;

/**
 * 一只青蛙一次可以跳上1级台阶，也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法（先后次序不同算不同的结果）
 * F(n)={0,               n=0
 * 1,                n=1
 * 2,                n=2
 * F(n−1)+F(n−2),    n>2
 *
 * @version 1.0.0
 * @Author yong.Mr
 * @data 2021-03-13
 */
public class 跳台阶 {

    public static int jumpFloor(int target) {
        if (target < 3) {
            return target;
        }
        int a = 2;
        int b = 1;
        int temp = 0;
        for (int i = 3; i <= target; i++) {
            temp = a + b;
            b = a;
            a = temp;

        }
        return a;
    }

    public static int jump(int target) {
        if (target <= 2) {
            return target;
        }
        return jump(target - 1) + jump(target - 2);
    }

    public static void main(String[] args) {
        System.out.println(jumpFloor(10));
    }
}
